package ${packageCode}.${moduleMapperCode}.func.${businessCode?uncap_first}.webapi.v1;

import com.google.common.collect.Maps;
import org.springframework.stereotype.Component;
import ${packageCode}.${moduleMapperCode}.dto.${businessCode}Dto;
import ${packageCode}.${moduleMapperCode}.service.${businessCode}Service;
import top.cardone.context.ApplicationContextHolder;
import top.cardone.core.util.func.Func1;

import java.util.Map;

/**
 * ${businessName!} - 查询
 */
@Component("/web-api/v1/${moduleMapperCode}/${businessCode?uncap_first}/r0004.json")
public class R0004Func implements Func1<Object, Map<String, Object>> {
    @Override
    public Object func(Map<String, Object> map) {
        ${businessCode}Dto ${businessCode?uncap_first}Dto = ApplicationContextHolder.getBean(${businessCode}Service.class).findOne(${businessCode}Dto.class, map);

        return this.toMap(${businessCode?uncap_first}Dto);
    }

    private Map<String, Object> toMap(${businessCode}Dto ${businessCode?uncap_first}Dto) {
        Map<String, Object> map = Maps.newHashMap();

<#if entityMapper.fieldMapperMap??>
    <#list entityMapper.fieldMapperMap?values as fieldMapper>
        map.put("${fieldMapper.code}", ${businessCode?uncap_first}Dto.get${fieldMapper.code?cap_first}());
    </#list>
</#if>

        return map;
    }
}